{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:09:52.234930Z",
     "start_time": "2024-05-11T08:09:52.226960Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ],
   "id": "626917f5f831a128",
   "execution_count": 86,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "a = [1,2,3]\n",
    "a = pd.Series(a)\n",
    "a"
   ],
   "id": "initial_id",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "b = pd.read_clipboard()\n",
    "b"
   ],
   "id": "38533a2f3651837",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "c = pd.DataFrame(b, columns=[\"排名\", \"编程语言\"])\n",
    "c"
   ],
   "id": "397b7ae57771003a",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "b.index",
   "id": "b4f7118761f52a6a",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "sb = b[\"排名\"]\n",
    "sb"
   ],
   "id": "6c291d4ca6c4b5e5",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "sb.values",
   "id": "d9fc9d2fd47910c2",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "sb.index",
   "id": "9dd16c4d5aaf1a22",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "b.to_csv(\"./language.csv\")",
   "id": "adeba3b66fc33619",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "c = pd.read_csv(\"language.csv\")\n",
    "c"
   ],
   "id": "bd8927afd7f99b85",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "pops_df = pd.read_csv(\"country_population.csv\", names=[\"sName\", \"rank\", \"name\", \"count\", \"\"])\n",
    "pops_df = pops_df[[\"sName\", \"rank\", \"name\", \"count\"]]\n",
    "pops_df.head()"
   ],
   "id": "d35dea9bac969508",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "pops_df.tail()",
   "id": "6faf78d949dfd6c1",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "pops_df.iloc[10:20]",
   "id": "949ee037041aed5",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "pops_df.iloc[10:20, 0:1]",
   "id": "8164efd92bb116fd",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "pops_df.loc[13:15]",
   "id": "d03cd8e89f7f9541",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "raw",
   "source": "Series Reindex",
   "id": "75c8052dbe158618"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "s1 = pd.Series([1,2,3,4], index=[\"a\", \"b\", \"c\", \"d\"])\n",
    "s1"
   ],
   "id": "2f4c1b843e06e0b5",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "s1.reindex([\"a\", \"b\", \"c\", \"d\", \"e\"], fill_value=10)",
   "id": "ff12b61e2f7ce207",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "s2 = pd.Series([\"a\", \"b\", \"c\"], index=[1,5,10])\n",
    "s2"
   ],
   "id": "fdd1891544656d3c",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "s2.reindex(index=range(15), method=\"ffill\")",
   "id": "f3998a4f7b2c193",
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "raw",
   "source": "DataFrame Reindex",
   "id": "2afe2db03eaa8697"
  },
  {
   "metadata": {},
   "cell_type": "raw",
   "source": "NAN",
   "id": "ef0393427e337e69"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:09:55.843396Z",
     "start_time": "2024-05-11T08:09:55.824879Z"
    }
   },
   "cell_type": "code",
   "source": [
    "s1 = pd.Series([1,2,np.nan,4,5], index=[\"a\", \"b\", \"c\", \"d\", \"e\"])\n",
    "s1"
   ],
   "id": "77b89de02bb89f56",
   "execution_count": 87,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:10:09.286341Z",
     "start_time": "2024-05-11T08:10:09.263321Z"
    }
   },
   "cell_type": "code",
   "source": "s1.isnull()",
   "id": "3dc157008eab2d29",
   "execution_count": 89,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:10:20.506523Z",
     "start_time": "2024-05-11T08:10:20.486751Z"
    }
   },
   "cell_type": "code",
   "source": "s1.notnull()",
   "id": "98a7894a643f1f01",
   "execution_count": 90,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:10:36.682059Z",
     "start_time": "2024-05-11T08:10:36.668059Z"
    }
   },
   "cell_type": "code",
   "source": "s1.dropna()",
   "id": "d58c1b1cc9702534",
   "execution_count": 91,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:13:00.717989Z",
     "start_time": "2024-05-11T08:13:00.705505Z"
    }
   },
   "cell_type": "code",
   "source": [
    "df1 = pd.DataFrame(np.random.randn(5,3), index=[\"a\", \"b\", \"c\", \"d\", \"e\"], columns=[\"one\", \"two\", \"three\"])\n",
    "df1"
   ],
   "id": "7c4ca87330e5cfcc",
   "execution_count": 95,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:14:13.118964Z",
     "start_time": "2024-05-11T08:14:13.095200Z"
    }
   },
   "cell_type": "code",
   "source": [
    "df2 = df1.reindex([\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"])\n",
    "df2"
   ],
   "id": "965d692b0ae4eb30",
   "execution_count": 102,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:15:13.392201Z",
     "start_time": "2024-05-11T08:15:13.380745Z"
    }
   },
   "cell_type": "code",
   "source": "df3 = df2.reindex(columns=[\"one\", \"two\", \"three\", \"four\"])",
   "id": "faa32ad427797209",
   "execution_count": 107,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:15:16.631236Z",
     "start_time": "2024-05-11T08:15:16.616181Z"
    }
   },
   "cell_type": "code",
   "source": "df3.isnull()",
   "id": "cf0a8922f55c66fc",
   "execution_count": 108,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:15:19.673619Z",
     "start_time": "2024-05-11T08:15:19.661516Z"
    }
   },
   "cell_type": "code",
   "source": "df3.notnull()",
   "id": "8a654ab756e1d82c",
   "execution_count": 109,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:17:38.485432Z",
     "start_time": "2024-05-11T08:17:38.463344Z"
    }
   },
   "cell_type": "code",
   "source": "df3.dropna(axis=0, how=\"all\")",
   "id": "ab526d246911b789",
   "execution_count": 114,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-11T08:17:59.016073Z",
     "start_time": "2024-05-11T08:17:58.992109Z"
    }
   },
   "cell_type": "code",
   "source": "df3.dropna(axis=1, how=\"all\")",
   "id": "d9bdece32f6212c7",
   "execution_count": 115,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "execution_count": null,
   "source": "",
   "id": "452d155aff66fd81",
   "outputs": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
